﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace CMS
{
    [Serializable]
    public class Users
    {
        public long? USR_ID { get; set; }
        public string USR_NAME { get; set; }
        public string USR_PASSWORD { get; set; }
        public string USR_EMAIL { get; set; }
        public long? ADM_ID { get; set; }
        public Boolean? USR_ACTIVE { get; set; }
        
        public string USR_LASTLOGIN { get; set; }
        public Boolean? USR_MASTERUSER { get; set; }

        #region Constructors
        /// <summary>
        /// Creates a new instance of an Page object.
        /// </summary>
        public Users() : this(null) { }

        /// <summary>
        /// Creates a new instance of an Page object.
        /// </summary>
        public Users(long? id)
        {
            USR_ID = id;
        }
        #endregion

        /// <summary>
        /// Returns a list of Pages.
        /// </summary>
        public static List<CMS.Users> GetUsers(Int64? USR_ID, String USR_NAME, String USR_PASSWORD, String Email, Int64? ADM_ID, Boolean? USR_ACTIVE, string USR_LASTLOGIN, Boolean? USR_MASTERUSER)
        {
            DataTable StoredProcedureTablePages = CMS.StoredProcedureValues.VW_Users(USR_ID, USR_NAME, USR_PASSWORD, Email, ADM_ID, USR_ACTIVE, USR_LASTLOGIN, USR_MASTERUSER);
            return GetListUsers(StoredProcedureTablePages);
        }

        /// <summary>
        /// Converts a DataTable into a list of Pages.
        /// </summary>
        public static List<CMS.Users> GetListUsers(DataTable StoredProcedureTable)
        {
            List<CMS.Users> OutPages = new List<CMS.Users>();

            for (int i = 0; i < StoredProcedureTable.Rows.Count; i++)
            {
                CMS.Users Users = new CMS.Users();
                DataRow Row = StoredProcedureTable.Rows[i];

                Users.USR_ID = Convert.ToInt64((Row["USR_ID"]));
                Users.USR_NAME = Row["USR_NAME"].ToString();
                Users.USR_PASSWORD = Row["USR_PASSWORD"].ToString();
                Users.USR_EMAIL = Row["USR_EMAIL"].ToString();
                Users.ADM_ID = Convert.ToInt64((Row["ADM_ID"]));
                Users.USR_ACTIVE = CMS.Functions.NullableBoolean(Row["USR_ACTIVE"]);
                Users.USR_LASTLOGIN = Row["USR_LASTLOGIN"].ToString();
                Users.USR_MASTERUSER = CMS.Functions.NullableBoolean(Row["USR_MASTERUSER"]);

                OutPages.Add(Users);
            }

            return OutPages;
        }
    }
}